<?php

namespace Modules\Admin\Http\Controllers;

use HiCommon\Repository\ConfigPrivateRepository;
use Illuminate\Support\Facades\Request;

class ConfigController extends BaseController
{

    /*私有配置*/
    public function config_private_set(){
        try {
            $arr_input = Request::input();
            arr_trim($arr_input);

            $arr_tab = [
              'jsfl'=>'结算费率',
              'join_subheading'=>'加盟副标题',
            ];

            $action = str_trim($arr_input['action']);
            if($action == 'do'){
                $arr_input['id'] = 1;

                //修改操作
                if(isset($arr_input['settle_service_fee_rate'])){
                    $arr_input['settle_service_fee_rate'] = number_format(intval($arr_input['settle_service_fee_rate'])/1000,4);
                }
                $res = ConfigPrivateRepository::base_edit_one($arr_input);

                if($res === false){
                    return hello_error('操作失败');
                }

                //刷新redis费率缓存
                redis_refresh_settle_service_fee_rate();
                return  hello_success('成功');
            }
            else{
                //页面展示
                $result = ConfigPrivateRepository::base_find_one(1)->toarray();
                $result['settle_service_fee_rate'] = intval($result['settle_service_fee_rate']*1000);

                if (empty($arr_input['tab_type'])){
                    $arr_input['tab_type'] = 'jsfl';
                }
                $arr_data = [
                  'data'=>$result,
                  'arr_tab'=>$arr_tab,
                  's_tab_type'=>$arr_input['tab_type']
                ];
                return view('admin::config.config_private_set',$arr_data);
            }

        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }





}
